package ystp.service;

import org.springframework.stereotype.Service;
import ystp.dao.YsrenyuanfenpeiMapper;
import ystp.model.Ysrenyuanfenpei;
import ystp.model.YsrenyuanfenpeiExample;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class YsrenyuanfenpeiService {

    @Resource
    YsrenyuanfenpeiMapper ddMapper;

    public List<Map<String, Object>> findRenyuanFenpeiByXiangmuId(String mmxiangmuId){
        return ddMapper.findRenyuanFenpeiByXiangmuId(mmxiangmuId);
    }

    public Ysrenyuanfenpei findOne(String ppid){return ddMapper.selectByPrimaryKey(ppid);}

    public boolean add(Ysrenyuanfenpei ppYsrenyuanfenpei){
        return ddMapper.insert(ppYsrenyuanfenpei)==1;
    }

    public boolean update(Ysrenyuanfenpei ppYsrenyuanfenpei){
        return ddMapper.updateByPrimaryKey(ppYsrenyuanfenpei)==1;
    }
    public boolean updateByPrimaryKeySelective(Ysrenyuanfenpei ppYsrenyuanfenpei){
        return ddMapper.updateByPrimaryKeySelective(ppYsrenyuanfenpei)==1;
    }
    public boolean delete(String ppId){
        return ddMapper.deleteByPrimaryKey(ppId)>=0;
    }

    public boolean deleteByXiangmuid(String ppxianmguId){
        return ddMapper.deleteByXiangmuid(ppxianmguId)>=0;
    }

    public List<Ysrenyuanfenpei>  findbyUserIDandXiangmuId(String ppuserId,String ppxianmguId){
        YsrenyuanfenpeiExample mmExample=new YsrenyuanfenpeiExample();
        YsrenyuanfenpeiExample.Criteria criteria = mmExample.createCriteria();
        criteria.andUseridEqualTo(ppuserId).andXiangmuidEqualTo(ppxianmguId);
        return ddMapper.selectByExample(mmExample);
    }
    public List<Ysrenyuanfenpei>  findUserNumberByXiangmuId(String ppxianmguId){
        YsrenyuanfenpeiExample mmExample=new YsrenyuanfenpeiExample();
        YsrenyuanfenpeiExample.Criteria criteria = mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(ppxianmguId);
        return ddMapper.selectByExample(mmExample);
    }

    public List<Ysrenyuanfenpei> findUserByXiangmuId(String ppxianmguId){
        YsrenyuanfenpeiExample mmExample=new YsrenyuanfenpeiExample();
        YsrenyuanfenpeiExample.Criteria criteria = mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(ppxianmguId);
        return ddMapper.selectByExample(mmExample);
    }


    public Integer getSubmitedCount(String ppxianmguId){
        YsrenyuanfenpeiExample mmExample=new YsrenyuanfenpeiExample();
        YsrenyuanfenpeiExample.Criteria criteria = mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(ppxianmguId).andIssubmitEqualTo(1);
        return ddMapper.selectByExample(mmExample)==null?0:ddMapper.selectByExample(mmExample).size();
    }

}
